<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Trx
 * Class untuk menangai transaksi
 * @author Massri
 */
class Application_Model_Trx {

    //put your code here

    private $_db;

    function __construct() {
        $registry = Zend_Registry::getInstance();
        $this->_db = $registry->database;
    }

    /*
     * $trx array ('header'=> array(),
     *              'detail'=> array())
     */

    public function create($trx) {

        try {
            $header = $trx['header'];

            $this->_db->insert('trans_header', $header);

            $headerId = $this->_db->lastInsertId();

            $detail = $trx['detail'];
            $this->_db->insert('trans_detail', $detail);

            return $headerId;
        } catch (Exception $e) {
            return $e->getCode();
        }
    }

}
